package com.example.sms.controller;

import com.example.common.redis.service.RedisService;
import com.example.common.util.core.controller.BaseController;
import com.example.common.util.core.resultbody.AjaxResult;
import com.example.common.util.utils.StringUtils;
import com.example.sms.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author juzipi
 * @Date 2021/7/17 14:32
 * @Info
 */
@Api(tags = "短信")
@RestController
@RequestMapping("api/sms/message")
public class SmsController extends BaseController {


    @Autowired
    private RedisService redisService;

    @Autowired
    private SmsService smsService;


    @ApiOperation("发送短信")
    @PostMapping("send/{phone}")
    public AjaxResult sendCode(@PathVariable String phone){
        //先验证redis里有没有验证码
        if (StringUtils.isNotEmpty(phone) && StringUtils.isNull(redisService.getCacheObject(phone))){
            return toAjax(smsService.sendCode(phone));
        }
        return AjaxResult.success();
    }


}
